package com.example.controller;

import com.example.common.Result;
import com.example.entity.BuyTicketsInfo;
import com.example.entity.TicketDto;
import com.example.service.TicketService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/ticket")
public class TicketController {

    @Autowired
    TicketService ticketService;

    /**
     * 新增
     */

    @PostMapping("/add")
    public Result add (@RequestBody TicketDto ticketDto){
        ticketService.add(ticketDto);
        return Result.success();
    }
    /**
     * 插入买票记录
     */
    @PostMapping("/addtickets")
    public Result buyTickets (@RequestBody BuyTicketsInfo buyTicketsInfo  ){
        ticketService.buyTickets(buyTicketsInfo);
        return Result.success();
    }
    /**
     * 删除
     */

    @DeleteMapping("/delete/{id}")
    public Result delete (@PathVariable Integer id){
        ticketService.deleteById(id);
        return Result.success();
    }
    /**
     * 更新
     */

    @PutMapping("/update")
    public  Result update (@RequestBody TicketDto ticketDto)
    {
        ticketService.updateById(ticketDto);
        return Result.success();
    }
    /**
     * 列表
     */

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10")Integer pageSize,
                             String gameName, String gameType){
        PageInfo<TicketDto> PageInfo = ticketService.selectPage(pageNum,pageSize, gameName,gameType);
        return Result.success(PageInfo);
    }

    @GetMapping("/selectPageTickets")
    public Result selectPageTickets(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10")Integer pageSize,
                             String gameId, String userId,String userRole,Integer userYonghuId){
        PageInfo<BuyTicketsInfo> PageInfo = ticketService.selectPageTickets( pageNum,pageSize, gameId,userId,userRole,userYonghuId);
        return Result.success(PageInfo);
    }
}
